package com.qf2210.group.three.server.mapper;

import com.qf2210.group.three.pojo.Good;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf2210.group.three.utils.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author len
 * @description 针对表【tb_good】的数据库操作Mapper
 * @createDate 2022-12-01 21:36:13
 * @Entity com.qf2210.group.three.pojo.Good
 */
public interface GoodMapper extends BaseMapper<Good> {
    /**
     * 分页查询
     * @param cId
     * @param bId
     * @param start
     * @param end
     * @return
     */
    @Select("SELECT * FROM `tb_good` \n" +
            "WHERE good_id IN (\n" +
            "SELECT fk_good_id FROM  \n" +
            "tb_brand_good WHERE fk_brand_id =#{bId} AND fk_brand_id IN\n" +
            "(SELECT fk_brand_id  FROM `tb_category_brand` WHERE fk_category_id =#{cId}) ) LIMIT #{start},#{end}")
    List<Good> getGoods(@Param("cId") int cId, @Param("bId") int bId, @Param("start") int start, @Param("end") int end);

    /**
     * 查询总记录数
     * @param cId
     * @param bId
     * @return
     */
    @Select("SELECT count(*) FROM `tb_good` \n" +
            "WHERE good_id IN (\n" +
            "SELECT fk_good_id FROM  \n" +
            "tb_brand_good WHERE fk_brand_id =#{bId} AND fk_brand_id IN\n" +
            "(SELECT fk_brand_id  FROM `tb_category_brand` WHERE fk_category_id =#{cId}) \n" +
            "\t) ")
    int getCounts(@Param("cId") int cId, @Param("bId") int bId);
}




